# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: xguo

import json
import logging
import os

from coin2.support.product_info.spot_coinone_v2 import convert_coin1_constants


error_code = {
    4:
        'Blocked user access',
    8:
        'Request Token Parameter is needed',
    11:
        'Access token is missing',
    12:
        'Invalid access token',
    40:
        'Invalid API permission',
    51:
        'Invalid API <- 없음',
    53:
        'Two Factor Auth Fail',
    101:
        'Invalid format',
    103:
        'Lack of Balance',
    104:
        'Order id is not exist',
    105:
        'Price is not correct',
    107:
        'Parameter error',
    113:
        'Quantity is too low(ETH, ETC > 0.01)',
    120:
        'V2 API payload is missing',
    121:
        'V2 API signature is missing',
    122:
        'V2 API nonce is missing',
    123:
        'V2 API signature is not correct',
    130:
        'V2 API Nonce value must be a positive integer',
    131:
        'V2 API Nonce is must be bigger then last nonce',
    132:
        'V2 API body is corrupted',
    150:
        "It's V1 API. V2 Access token is not acceptable",
    151:
        "It's V2 API. V1 Access token is not acceptable",
    405:
        'Server error',
    1201:
        'API Deprecated',
    1206:
        'User not found',
    11003:
        'Unknown cryptocurrency.',
    11014:
        'The service is temporarily not offered.',
    11015:
        'The order limit price cancellation denied.',
    11016:
        'The order cancellation denied.',
    11017:
        'This is not a valid input value.',
    11025:
        'The cryptocurrency is not supported.',
    11062:
        'This is not a valid the fund-raising period of time.',
    11063:
        'This is not a valid the fund-raising amount.',
    11064:
        'It has not been fundraising information.',
    11065:
        'It is not the fundraiser now.',
    11066:
        'The fundraising has been done.',
    11067:
        'The fundraising has been done for goal amount.',
    11074:
        'This is not a valid your ID.',
    11075:
        'For the safe trading environment, orders are limited for a notified period of time.',
    11076:
        'For the safe trading environment, sell orders can be placed after a notified period of time.',  # noqa: E501
    11077:
        'For the safe trading environment, buy orders can be placed after a notified period of time.',  # noqa: E501
    11078:
        'For the safe trading environment, sell orders below the certain price criteria notified are limited.',  # noqa: E501
    11079:
        'For the safe trading environment, sell orders above the certain price criteria notified are limited.',  # noqa: E501
    11080:
        'For the safe trading environment, boy orders below the certain price criteria notified are limited.',  # noqa: E501
    11081:
        'For the safe trading environment, buy orders above the certain price criteria notified are limited.',  # noqa: E501
    11082:
        'The order quantity is non-cancelable.',
    11083:
        'Your order amount is less than minimum amount.(500 KRW)'
}


pi_file = 'data/coin2/product_info/Spot.Coinone.v2.json'
with open(pi_file) as f:
  static_constants = convert_coin1_constants(json.load(f)['product_infos'])

dynamic_constants = {}
if int(os.getenv('USE_DYNAMIC_SYMBOL', 0)):
  try:
    from coin2.support.product_info.spot_coinone_v2 import gen_coin1_constants
    dynamic_constants = gen_coin1_constants()
    orderbook_unit_map = dynamic_constants['orderbook_unit_map']
  except Exception as e:
    logging.error('Failed to use coinone dynamic symbols! %s', e)

native_coin_list = list(set(
    static_constants.get('native_coin_list', []) +
    dynamic_constants.get('native_coin_list', [])))
native_currency_list = native_coin_list + ['krw']
